package rabbit.work;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import rabbit.util.RabbitMqUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Work01
 * Package: rabbit.work
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-25
 * Time: 15:43
 */

public class Work01 {
    //一个工作线程 消费者

    public static final String QUEUE_NAME = "hello";

    //接收消息
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel chanel = RabbitMqUtils.getChanel();

        //消费者接收到消息的回调
        //收到的接收
        DeliverCallback deliverCallback = (consumerTag,message) ->{
            System.out.println("接收到的消息: " + new String(message.getBody()));
        };

        //消息接收被取消时
        CancelCallback cancelCallback = (consumerTage) ->{
            System.out.println(consumerTage + "消息被取消的回调内容");
        };

        System.out.println("C2 等待接收消息: ");
        chanel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }

}
